package org.example.sunrise.views.models;

import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.util.converter.NumberStringConverter;
import org.example.sunrise.converters.EmploymentRequestConverter;
import org.example.sunrise.domains.EmploymentRequest;
import org.example.sunrise.models.EmploymentRequestModel;

public class EmploymentRequestViewModel {
    private final StringProperty name = new SimpleStringProperty("");
    private final StringProperty position = new SimpleStringProperty("");
    private final DoubleProperty annualSalary = new SimpleDoubleProperty();
    private final EmploymentRequestModel model = new EmploymentRequestModel();
    private final EmploymentRequestConverter converter = new EmploymentRequestConverter();

    public void bindNameProperty(StringProperty property) {
        property.bindBidirectional(name);
    }

    public void bindPositionProperty(StringProperty property) {
        property.bindBidirectional(position);
    }

    public void bindAnnualSalaryProperty(StringProperty property) {
        property.bindBidirectional(annualSalary, new NumberStringConverter());
    }

    public void reset() {
        this.name.set("");
        this.position.set("");
        this.annualSalary.set(0.0d);
    }

    public void save() {
        EmploymentRequest data = converter.toEmploymentRequest(this);
        model.save(data);
    }

    public String getPosition() {
        return position.get();
    }

    public String getName() {
        return name.get();
    }

    public Double getAnnualSalary() {
        return annualSalary.get();
    }
}
